<?php
global $db;
global $db_connection;
$db_connection = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name']);

if(mysqli_connect_errno()) 
{
    die('Database Server Error!');
}
/**
 *
 * @return mysqli_connection 
 */
function getDB()
{
	global $db_connection;
	return $db_connection;
}

function dbQuery($sql, $type = 'select')
{
    global $db;
    if($db === null) return false;
    
    $result = mysqli_query($db, $sql);
    switch ($type)
    {
        case 'select':
            $list = array();
            while($row = mysqli_fetch_assoc($result))
            {
                $list[] = $row;
            }
            break;
        case 'insert':
        case 'delete':
        case 'update':
            return $result;
            break;
        default:
            return false;
    }
}
?>